package base.thread_JUC2.chapter04.demo09;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

//任务结束后的操作控制
public class ResultTask extends FutureTask<String> {

    private String name;

    public ResultTask(@NotNull Callable<String> callable) {
        super(callable);
        this.name = ((ExecutableTask)callable).getName();
    }

    @Override
    protected void done(){
        if (isCancelled()) {
            System.out.printf("%s: 任务已取消\n",name);
        }else{
            System.out.printf("%s: 任务已结束\n",name);
        }
    }
}
